package cn.jiemusic.service.impl;

import cn.jiemusic.common.CustomException;
import cn.jiemusic.domain.po.Music;
import cn.jiemusic.domain.po.UserLike;
import cn.jiemusic.mapper.UserLikeMapper;
import cn.jiemusic.service.MusicService;
import cn.jiemusic.service.UserLikeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class UserLikeServiceImpl extends ServiceImpl<UserLikeMapper, UserLike> implements UserLikeService {
    @Override
    public void addLikeSong(String uid, String sid) {
        UserLike userLike = getById(uid);

        List<Long> likeSong = userLike.getLikeSong();

       //如果以收藏就直接返回
        if (likeSong.contains(Long.valueOf(sid))) return;

        likeSong.add(Long.parseLong(sid));

        userLike.setLikeSong(likeSong);
        updateById(userLike);
    }

    @Override
    public void delSong(String uid, String sid) {
        UserLike userLike = getById(uid);

        List<Long> likeSong = userLike.getLikeSong();
        likeSong.remove(Long.parseLong(sid));

        userLike.setLikeSong(likeSong);
        updateById(userLike);
    }

}
